#ifndef __THREAD_HPP__
#define __THREAD_HPP__

#include <functional>
#include <cassert>
#include <pthread.h>
#include <vector>
#include <string>
#include <queue>


using func_t = std::function<void()>;

class Thread
{
    void Execute()
    {
        _func();
    }
    public:
    Thread(func_t func,std::string threadname = "Unknown"):_func(func),_threadname(threadname)
    {}
    static void* threadroutine(void* args)
    {
        Thread* self = static_cast<Thread*>(args);
        self->Execute();
        return nullptr;
    }
    void Start()
    {
        int n = pthread_create(&_tid,nullptr,threadroutine,this);
        assert(!n);
    }
    void Join()
    {
        int n = pthread_join(_tid,nullptr);
        assert(!n);
    }
    std::string name()
    {
        return _threadname;
    }

    private:
        pthread_t _tid;
        std::string _threadname;
        func_t _func;
};

#endif